﻿Imports System.Data.SqlClient
Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Label2.Text = Session("username")
            Dim ID As String = Request.QueryString("id")

            If (ID >= 1) Then ' we started imageid from 1
                Dim cmd As New SqlCommand("select * from imagetable where imageid=" + ID, cn)
                Dim dr As SqlDataReader
                cn.Open()
                dr = cmd.ExecuteReader
                dr.Read()
                Image1.ImageUrl = dr("imageurl")
                Image1.Height = 500
                Image1.Width = 500
                cn.Close()
            End If
            Dim sql As String = "select Title,Description,UploadDate,UploadBy FROM IMAGETABLE WHERE IMAGEID=" + ID
            Dim sd1 As New SqlDataSource(cn.ConnectionString, sql)
            DetailsView1.DataSource = sd1
            DetailsView1.DataBind()
        Catch ex As Exception

        End Try


    End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Session("username") = "Guest" Then
            Label3.Text = "Login First"
        Else
            Try
                cn.Open()
                Dim x As Integer
                x = functions.addcomments("insert into comment(imageid,commentby,comment,cdate) values('" + Request.QueryString("id") + "','" + Session("username") + "','" + TextBox1.Text + "','" + DateTime.Now)
                cn.Close()
                Label3.Text = "Comment Added !"
                TextBox1.Text = ""
            Catch ex As Exception

            End Try
        End If

    End Sub
End Class
